package com.zgy.myshellcommand.command;


import com.zgy.myshellcommand.anno.CommandConfig;
import com.zgy.myshellcommand.enums.F2eOptionsEnum;
import com.zgy.myshellcommand.handler.FileToExcelHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.shell.command.CommandRegistration;

@CommandConfig
public class FileToExcelCommand {

    @Autowired
    private FileToExcelHandler fileToExcelHandler;

    @Bean
    CommandRegistration f2e(){
        return CommandRegistration.builder()
                .command(F2eOptionsEnum.Command.getLongName())
                .group(F2eOptionsEnum.Command.getGroup())
                .description(F2eOptionsEnum.Command.getDescription())
                .withTarget()
                .consumer(ctx->fileToExcelHandler.f2eHandle(ctx))
                .and()
                //help
                .withHelpOptions()
                .longNames("help")
                .shortNames('h')
                .command(F2eOptionsEnum.Command.getLongName())
                .and()
                .build();
    }

    @Bean
    CommandRegistration f2eCmd(){
        return CommandRegistration.builder()
                .command(F2eOptionsEnum.Command.getLongName(),F2eOptionsEnum.Cmd.getSubCommandName())
                .description(F2eOptionsEnum.Cmd.getDescription())
                .group(F2eOptionsEnum.Cmd.getGroup())
                //参数ModuleExcel
                .withOption()
                .longNames(F2eOptionsEnum.ModuleExcel.getLongName())
                .arity(CommandRegistration.OptionArity.NONE)
                .description(F2eOptionsEnum.ModuleExcel.getDescription())
                .and()
                //参数InsertExcel
                .withOption()
                .longNames(F2eOptionsEnum.InsertExcel.getLongName())
                .arity(CommandRegistration.OptionArity.NONE)
                .description(F2eOptionsEnum.InsertExcel.getDescription())
                .and()
                //CommitRow
                .withOption()
                .longNames(F2eOptionsEnum.CommitRow.getLongName())
                .arity(CommandRegistration.OptionArity.NONE)
                .description(F2eOptionsEnum.CommitRow.getDescription())
                .defaultValue(F2eOptionsEnum.CommitRow.getDefaultValue())
                .type(Integer.class)
                .and()
                //SheetName
                .withOption()
                .longNames(F2eOptionsEnum.SheetName.getLongName())
                .arity(CommandRegistration.OptionArity.NONE)
                .description(F2eOptionsEnum.SheetName.getDescription())
                .defaultValue(F2eOptionsEnum.SheetName.getDefaultValue())
                .and()
                //DataFileName
                .withOption()
                .longNames(F2eOptionsEnum.DataFileName.getLongName())
                .arity(CommandRegistration.OptionArity.NONE)
                .description(F2eOptionsEnum.DataFileName.getDescription())
                .and()
                //DataFileFieldSeparator
                .withOption()
                .longNames(F2eOptionsEnum.DataFileFieldSeparator.getLongName())
                .arity(CommandRegistration.OptionArity.NONE)
                .description(F2eOptionsEnum.DataFileFieldSeparator.getDescription())
                .defaultValue(F2eOptionsEnum.DataFileFieldSeparator.getDefaultValue())
                .and()
                //DataFileCharSet
                .withOption()
                .longNames(F2eOptionsEnum.DataFileCharSet.getLongName())
                .arity(CommandRegistration.OptionArity.NONE)
                .description(F2eOptionsEnum.DataFileCharSet.getDescription())
                .defaultValue(F2eOptionsEnum.DataFileCharSet.getDefaultValue())
                .and()
                //DataFileNumberTypeCols
                .withOption()
                .longNames(F2eOptionsEnum.DataFileNumberTypeCols.getLongName())
                .arity(CommandRegistration.OptionArity.NONE)
                .description(F2eOptionsEnum.DataFileNumberTypeCols.getDescription())
                .defaultValue(F2eOptionsEnum.DataFileNumberTypeCols.getDefaultValue())
                .and()
                //ExcelStartRowNum
                .withOption()
                .longNames(F2eOptionsEnum.ExcelStartRowNum.getLongName())
                .arity(CommandRegistration.OptionArity.NONE)
                .description(F2eOptionsEnum.ExcelStartRowNum.getDescription())
                .defaultValue(F2eOptionsEnum.ExcelStartRowNum.getDefaultValue())
                .type(Integer.class)
                .and()
                //ExcelStartColNum
                .withOption()
                .longNames(F2eOptionsEnum.ExcelStartColNum.getLongName())
                .arity(CommandRegistration.OptionArity.NONE)
                .description(F2eOptionsEnum.ExcelStartColNum.getDescription())
                .defaultValue(F2eOptionsEnum.ExcelStartColNum.getDefaultValue())
                .type(Integer.class)
                .and()
                //执行处理逻辑
                .withTarget()
                .function(ctx->fileToExcelHandler.cmdHandle(ctx))
                .and()
                //CmdEx 例子
                .withOption()
                .longNames(F2eOptionsEnum.CmdEx.getLongName())
                .shortNames(F2eOptionsEnum.CmdEx.getShortName())
                .description(F2eOptionsEnum.CmdEx.getDescription())
//                .arity(CommandRegistration.OptionArity.NONE)
                .and()
                .withHelpOptions()
                .longNames("help")
                .shortNames('h')
                .command("help")
                .and()
                .build();
    }


    @Bean
     CommandRegistration f2eFile(){
        return CommandRegistration.builder()
                .command(F2eOptionsEnum.Command.getLongName(),F2eOptionsEnum.file.getSubCommandName())
                .description(F2eOptionsEnum.file.getDescription())
                .group(F2eOptionsEnum.file.getGroup())
                //JsonPath json配置文件路径
                .withOption()
                .longNames(F2eOptionsEnum.JsonPath.getLongName())
                .description(F2eOptionsEnum.JsonPath.getDescription())
                .and()
                //JsonPathCharSet json配置文件的编码
                .withOption()
                .longNames(F2eOptionsEnum.JsonPathCharSet.getLongName())
                .description(F2eOptionsEnum.JsonPathCharSet.getDescription())
                .defaultValue(F2eOptionsEnum.JsonPathCharSet.getDefaultValue())
                .and()
                //fileEx 例子
                .withOption()
                .longNames(F2eOptionsEnum.FileEx.getLongName())
                .shortNames(F2eOptionsEnum.FileEx.getShortName())
                .description(F2eOptionsEnum.FileEx.getDescription())
                .arity(CommandRegistration.OptionArity.NONE)
                .and()
                //JsonFormat json文件配置格式
                .withOption()
                .longNames(F2eOptionsEnum.JsonFormat.getLongName())
                .description(F2eOptionsEnum.JsonFormat.getDescription())
                .arity(CommandRegistration.OptionArity.NONE)
                .and()
                //执行处理逻辑
                .withTarget()
                .function(ctx->fileToExcelHandler.fileHandle(ctx))
                .and()
                .withHelpOptions()
                .longNames("help")
                .shortNames('h')
                .command("help")
                .and()
                .build();

    }
}
